package com.itheima.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author MI
 * @ClassName OrderServiceImpl3.java
 * @createTime 2021年11月17日 22:38:00
 */
@Service
@Slf4j
public class OrderServiceImpl3 {

    @SentinelResource(value = "message", blockHandler = "blockHandler", fallback = "fallback")
    public String message(String name) {
        return "message";
    }

    //1 当前方法返回值和参数更原方法一致
    //2 允许在参数列表最后加入一个BlockException
    public String blockHandler(String name, BlockException e) {
        //自定义异常处理
        log.error("触发了 Blockexception 内容为{}", e);
        return "message-err";
    }

    public String fallback(String name, Throwable e) {
        //自定义异常处理
        log.error("触发了 Blockexception 内容为{}", e);
        return "message-err";
    }
}
